/* 公共表单效验规则 */
import Vue from 'vue'

let rules = {}

rules.NoEmpty = (msg) => {
	return {
		// required: true,
		message: msg,
		trigger: 'change',
		validator: (rule, value, callback) => {
			console.log(value);
			return !Vue.prototype.$tools.emptyValid(value);
		},
	}
}

/* 大于 等于0 的数 */
rules.positiveNum = (msg = '必须为正数', zero = false) => { //是否包含0   
	return {
		validator: (rule, value, callback) => {
			if (value < 0) {
				return false
			} else if (value === 0) { //是否包含0
				return zero ? true : false
			} else {
				return true;
			}
		},
		transform(value) {
			return Number(value)
		},
		message: msg,
		trigger: 'change'
	}
}

export default rules
